<?php

/*
Plugin Name: Welcome Back
Plugin URI: http://wpjam.net/item/welcome-back/
Description: 欢迎回来！
Version: 1.0
Author: WPBlazer
Author URI: http://wpblazer.com/
*/

add_action('wp_footer', 'welcome_back_footer');

function welcome_back_footer() {
	if ( is_singular() ) {
		$currentLocale = get_locale();
		if(!empty($currentLocale)) {
			$moFile = dirname(__FILE__) . "/welcome-back-" . $currentLocale . ".mo";
			if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('wpblng', $moFile);
		}
		if (isset($_COOKIE['comment_author_'.COOKIEHASH])) {
			$comment_author = $_COOKIE['comment_author_'.COOKIEHASH];
		} ?>
		<p class="welcomeback" style="float:none;display:none;">
			<?php printf( __( 'Welcome back, %1$s!', 'wpblng' ), $comment_author ) ?>
			<a id="toggleprofile" href="#">
				<span class="toggleo"><?php _e( 'Change', 'wpblng' ); ?> &raquo;</span>
				<span class="togglex" style="display:none;"><?php _e( 'Close', 'wpblng' ); ?> &laquo;</span>
			</a>
		</p>
		<script type="text/javascript">
			var welcomBack = $('#author').val();
			if(welcomBack){
				$('.welcomeback').remove().prependTo('#commentform').show();
				$('#guest_name, #guest_email, #guest_url').hide();
			}
			$('#toggleprofile').click(function(){
				$('.toggleo, .togglex').toggle();
				$('#guest_name, #guest_email, #guest_url').toggle(500);
				return false;
			});
		</script>
		<?php
	}
}

?>
